<?php

namespace app\admin\model\tongcheng;

use think\Model;


class SubscribeMessageModel extends Model
{


    // 表名
    protected $name = 'tongcheng_subscribe_message';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'client_text'
    ];


    public function getClientList()
    {
        return ['CUSTOMER' => __('Customer'), 'RIDER' => __('Rider')];
    }


    public function getClientTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['client']) ? $data['client'] : '');
        $list  = $this->getClientList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    /**
     * 根据场景获取模板ID
     * @param $scene
     * @return string[]
     */
    public static function getTemplateIdsByScene($scene)
    {
        if (!$scene) {
            return [];
        }
        return SubscribeMessageModel::where('scene', $scene)->column('template_id');
    }

    /**
     * 根据描述获取模板ID
     * @param $name
     * @return float|mixed|string
     */
    public static function getTemplateIdByName($name)
    {
        if (!$name) {
            return '';
        }
        return SubscribeMessageModel::where('name', $name)->value('template_id');
    }

}
